package com.lagou;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.io.IOException;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

public class JedisClusterTest {

    JedisCluster jedisCluster;

    @Before
    public void initJedisConnect() {
        Set<HostAndPort> nodes = new HashSet<>();
        nodes.add(new HostAndPort("192.168.198.8", 6380));
        nodes.add(new HostAndPort("192.168.198.8", 6381));
        nodes.add(new HostAndPort("192.168.198.8", 6382));
        nodes.add(new HostAndPort("192.168.198.8", 6386));
        jedisCluster = new JedisCluster(nodes);
    }

    @Test
    public void add() {
        String set = jedisCluster.set("user", "kim");
        System.out.println("set user success");
    }

    @Test
    public void get() {
        String user = jedisCluster.get("user");
        System.out.println(">>>>user:"+user);
    }

    @After
    public void closeJedisConnect() throws IOException {
        if (Objects.nonNull(jedisCluster))
            jedisCluster.close();
    }

}
